﻿using University.Workshop.Business;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.ObjectModel;
using University.Workshop.Model;
using University.Workshop.DataAccess;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for CompareProductsManagerTest and is intended
    ///to contain all CompareProductsManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CompareProductsManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for DeleteProduct
        ///</summary>
        [TestMethod()]
        public void DeleteProductTest()
        {
            Collection<long> prodIds = new Collection<long>();
            prodIds.Add(12);
            prodIds.Add(232);
            prodIds.Add(122);
            prodIds.Add(11);
            long prodId = 12; 
            Collection<long> expected = new Collection<long>();
            expected.Add(12);
            expected.Add(232);
            expected.Add(122);
            expected.Add(11);
            expected.Remove(12);
            Collection<long> actual;
            actual = CompareProductsManager.DeleteProduct(prodIds, prodId);
            Assert.AreEqual(expected.Contains(prodId), actual.Contains(prodId));
        }

        /// <summary>
        ///A test for GatherInformation
        ///</summary>
        [TestMethod()]
        public void GatherInformationTest()
        {
            Random rand = new Random();
            string email = "unCorreoMas" + rand.Next(500) + "@hotmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("minombre", "miapellido", 'M',
                                         birthday, email, "qwerty12", "qwerty12", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product actual1, actual2;
            string name = "Cellular smart phone y todo eso" + rand.Next(500);
            actual1 = ProductRegistrationManager.RegisterNewProduct(name, "120", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", user.Id, "1");
            actual2 = ProductRegistrationManager.RegisterNewProduct(name, "120", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", user.Id, "1");
            Collection<long> productIds = new Collection<long>();
            Collection<ComparedProduct> expected = new Collection<ComparedProduct>();
            ComparedProduct n1 = new ComparedProduct();
            ComparedProduct n2 = new ComparedProduct();
            n1.RelatedProduct = actual1;
            n2.RelatedProduct = actual2;
            expected.Add(n1);
            expected.Add(n2);
            productIds.Add(actual1.ProductId);
            productIds.Add(actual2.ProductId);
            Collection<ComparedProduct> actual;
            actual = CompareProductsManager.GatherInformation(productIds);
            Assert.AreEqual(expected[0].RelatedProduct.ProductId, actual[0].RelatedProduct.ProductId);

        }

        /// <summary>
        ///A test for GetIdsList
        ///</summary>
        [TestMethod()]
        public void GetIdsListTest()
        {
            Random rand = new Random();
            string email = "unCorreoMas" + rand.Next(500) + "@hotmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("minombre", "miapellido", 'M',
                                         birthday, email, "qwerty12", "qwerty12", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product actual1, actual2;
            string name = "Cellular smart phone y todo eso" + rand.Next(500);
            actual1 = ProductRegistrationManager.RegisterNewProduct(name, "120", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", user.Id, "1");
            actual2 = ProductRegistrationManager.RegisterNewProduct(name, "120", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", user.Id, "1");
            Collection<long> productIds = new Collection<long>();
            Collection<long> actual = new Collection<long>();
            Collection<ComparedProduct> compProducts = new Collection<ComparedProduct>();
            ComparedProduct n1 = new ComparedProduct();
            ComparedProduct n2 = new ComparedProduct();
            n1.RelatedProduct = actual1;
            n2.RelatedProduct = actual2;
            compProducts.Add(n1);
            compProducts.Add(n2);
            productIds.Add(actual1.ProductId);
            productIds.Add(actual2.ProductId);
            actual = CompareProductsManager.GetIdsList(compProducts);
            Assert.AreEqual(productIds[0], actual[0]);
        }

        /// <summary>
        ///A test for Reverse
        ///</summary>
        [TestMethod()]
        [DeploymentItem("University.Workshop.Business.dll")]
        public void ReverseTest()
        {
            string name = "telefonito bueno";
            Product actual1, actual2;
            actual1 = ProductRegistrationManager.RegisterNewProduct(name, "120", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", 1, "1");
            actual2 = ProductRegistrationManager.RegisterNewProduct(name, "120", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", 1, "1");
            ComparedProduct n1 = new ComparedProduct();
            ComparedProduct n2 = new ComparedProduct();
            n1.RelatedProduct = actual1;
            n2.RelatedProduct = actual2;
            Collection<ComparedProduct> compProducts = new Collection<ComparedProduct>();
            Collection<ComparedProduct> expected = new Collection<ComparedProduct>(); // TODO: Initialize to an appropriate value
            Collection<ComparedProduct> actual;
            compProducts.Add(n1);
            compProducts.Add(n2);
            expected.Add(n2);
            expected.Add(n1);
            
            actual = CompareProductsManager_Accessor.Reverse(compProducts);
            Assert.AreEqual(expected[0], actual[0]);
        }

        /// <summary>
        ///A test for SortBy
        ///</summary>
        [TestMethod()]
        public void SortByTest()
        {
            string name = "telefonito bonito";
            Product actual1, actual2;
            actual1 = ProductRegistrationManager.RegisterNewProduct(name, "154", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", 2, "1");
            actual2 = ProductRegistrationManager.RegisterNewProduct(name, "144", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars",2, "1");
            ComparedProduct n1 = new ComparedProduct();
            ComparedProduct n2 = new ComparedProduct();
            n1.RelatedProduct = actual1;
            n2.RelatedProduct = actual2;
            Collection<ComparedProduct> compProducts = new Collection<ComparedProduct>(); // TODO: Initialize to an appropriate value
            int sortType = 0; // TODO: Initialize to an appropriate value
            Collection<ComparedProduct> expected = new Collection<ComparedProduct>(); // TODO: Initialize to an appropriate value
            Collection<ComparedProduct> actual;
            expected.Add(n1);
            expected.Add(n2);
            compProducts.Add(n1);
            compProducts.Add(n2);
            actual = CompareProductsManager.SortBy(compProducts, sortType);
            Assert.AreEqual(expected[0], actual[0]);
        }

        /// <summary>
        ///A test for SortByLowestPrice
        ///</summary>
        [TestMethod()]
        [DeploymentItem("University.Workshop.Business.dll")]
        public void SortByLowestPriceTest()
        {
            string name = "telefonito bonito";
            Product actual1, actual2;
            actual1 = ProductRegistrationManager.RegisterNewProduct(name, "1000", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", 2, "1");
            actual2 = ProductRegistrationManager.RegisterNewProduct(name, "140", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", 2, "1");
            ComparedProduct n1 = new ComparedProduct();
            ComparedProduct n2 = new ComparedProduct();
            n1.RelatedProduct = actual1;
            n2.RelatedProduct = actual2;
            Collection<ComparedProduct> compProducts = new Collection<ComparedProduct>(); // TODO: Initialize to an appropriate value
            Collection<ComparedProduct> actual;
            compProducts.Add(n1);
            compProducts.Add(n2);
            actual = CompareProductsManager_Accessor.SortByLowestPrice(compProducts);
            Assert.AreEqual(140, actual[0].RelatedProduct.Price);
        }

        /// <summary>
        ///A test for SortByNewlyListed
        ///</summary>
        [TestMethod()]
        [DeploymentItem("University.Workshop.Business.dll")]
        public void SortByNewlyListedTest()
        {
            string name = "telefonito bonito";
            Product actual1, actual2;
            actual1 = ProductRegistrationManager.RegisterNewProduct(name, "1000", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", 2, "1");
            actual2 = ProductRegistrationManager.RegisterNewProduct(name, "140", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", 2, "1");
            ComparedProduct n1 = new ComparedProduct();
            ComparedProduct n2 = new ComparedProduct();
            n1.RelatedProduct = actual1;
            n2.RelatedProduct = actual2;
            Collection<ComparedProduct> compProducts = new Collection<ComparedProduct>(); // TODO: Initialize to an appropriate value
            Collection<ComparedProduct> actual;
            compProducts.Add(n1);
            compProducts.Add(n2);
            actual = CompareProductsManager_Accessor.SortByNewlyListed(compProducts);
            Assert.AreEqual(n1.RelatedProduct.ProductId, actual[0].RelatedProduct.ProductId);
        }

        /// <summary>
        ///A test for SortBySellerFromAToZ
        ///</summary>
        [TestMethod()]
        [DeploymentItem("University.Workshop.Business.dll")]
        public void SortBySellerFromAToZTest()
        {
            string name = "telefonito bonito";
            Product actual1, actual2;
            actual1 = ProductRegistrationManager.RegisterNewProduct(name, "1000", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", 1, "1");
            actual2 = ProductRegistrationManager.RegisterNewProduct(name, "140", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", 2, "1");
            ComparedProduct n1 = new ComparedProduct();
            ComparedProduct n2 = new ComparedProduct();
            n1.RelatedProduct = actual1;
            n2.RelatedProduct = actual2;
            Collection<ComparedProduct> compProducts = new Collection<ComparedProduct>(); // TODO: Initialize to an appropriate value
            Collection<ComparedProduct> actual;
            compProducts.Add(n1);
            compProducts.Add(n2);
            actual = CompareProductsManager_Accessor.SortBySellerFromAToZ(compProducts);
            Assert.AreEqual(n1.RelatedProduct.ProductId, actual[0].RelatedProduct.ProductId);
        }
    }
}
